(function ($) {
    $.extend({
        // 通用方法封装处理
        common: {
            // 判断字符串是否为空
            isEmpty: function (value) {
                if (value == null || this.trim(value) == "") {
                    return true;
                }
                return false;
            },
            // 判断字符串是否不为空
            isNotEmpty: function (value) {
                if (value == null || this.trim(value) == "") {
                    return false;
                }
                return true;
            },
            // 空格截取
            trim: function (value) {
                if (value == null) {
                    return "";
                }
                return value.toString().replace(/(^\s*)|(\s*$)|\r|\n/g,"");
            },
            // 数据字典
            initDity: function(_datas, _value) {
                var date = [];
                $.each(_datas, function(index, value) {
                    if (value.dictionaryRoute == _value) {
                        date.push("<span class='" + value.dictionaryClass + "'>" + value.dictionaryName + "</span>");
                        return false;
                    }
                });
                return date;
            },
            // 图标回显
            initIcon: function(_value) {
                return "<i class='" + _value + "'></i>";
            },
            // 状态回显
            initState: function(_datas,_value,id) {
                var layText='';
                $.each(_datas,function(index,value){
                    layText+=value.dictionaryName+'|';
                });
                layText = layText.substring(0,layText.length-1);
                if('Y' == _value || 'INTHEYOP' == _value ){
                    return '<input type="checkbox" lay-skin="switch"  lay-filter="*" lay-text="'+layText+'" id="'+id+'" checked >';
                }else{
                    return '<input type="checkbox" lay-skin="switch"  lay-filter="*" lay-text="'+layText+'" id="'+id+'">';
                }
            }
        },
        achieve:{
            /*post请求*/
            post:function(url,date,yesfunction,isindex) {
                Layer.showLogin();
                var length = arguments.length ;   //  实际传入参数的长度
                if(length == 2){
                    $.post(url, date,function (result) {
                        if(result && result.status == "success"){
                            Layer.showSucMsg(result.result);
                        }else{
                            Layer.showFailMsg(result.errorMsg);
                        }
                    }).error(function(){
                        Layer.showFailMsg("请求出现异常，请联系管理员！");
                    });
                }else if(length == 3) {
                    $.post(url, date, yesfunction).error(function(){
                        Layer.showFailMsg("请求出现异常，请联系管理员！");
                    });
                }else if(length == 4) {
                    $.post(url, date, function (result) {
                        if(result && result.status == "success"){
                            Layer.showSucMsg(result.result);
                            setTimeout("Layer.closeLayer()",1000);
                        }else{
                            Layer.showFailMsg(result.errorMsg);
                        }
                    }).error(function(){
                        Layer.showFailMsg("请求出现异常，请联系管理员！");
                    });
                }
            },
            postRefresh:function(url,date){
                Layer.showLogin();
                $.post(url, date, function (result) {
                    if(result && result.status == "success"){
                        Layer.showSucMsg(result.result);
                        setTimeout("location.reload();",1000);
                    }else{
                        Layer.showFailMsg(result.errorMsg);
                    }
                }).error(function(){
                    Layer.showFailMsg("请求出现异常，请联系管理员！");
                });
            },
            /*用户后台验证唯一性*/
            verifyPost:function (url,date) {
                var msg;
                $.ajax({
                    type: "post",
                    url: url,
                    async:false,
                    data:date,
                    success: function(result){
                        if(result.status != "success"){
                            msg = result.errorMsg;
                        }
                    }
                });
                return msg
            },
            /*post获取树形结构*/
            postTree:function (url,id) {
                $.post(url,function (result) {
                    if(result && result.status == "success"){
                        $.tree.init(id,result.result);
                    }
                })
            }

        },
        tree:{
            //初始化tree树
            init:function (id,value) {
                $(id).jstree({
                    'core': {
                        "animation" : 0,
                        "check_callback" : true,
                        "themes" : { "stripes" : true
                            ,"dots": true,
                            "icons": false},
                        'data': value
                    },
                    "plugins" : [
                        "contextmenu", "state","themes",
                        "wholerow"
                    ]
                });
            },
            //初始化复选框的tree树(支持多选)
            initCheckbox:function (id,value) {
                $(id).jstree({
                    "plugins":[ "wholerow", "checkbox" ],
                    'core':{
                        'data':value,
                        "themes" : { "stripes" : true
                            ,"dots": true,
                            "icons": false},
                    },
                    "checkbox" : {
                    },
                });
            }
        },
        /*时间工具类*/
        date:{
            stringDate:function(row){
                var sdf = new SimpleDateFormat();
                sdf.applyPattern("yyyy-MM-dd HH:mm:ss");
                var startTime = new Date(Date.parse(row));
                var strStart = sdf.format(startTime);
                return strStart;
            }
        },
    })
})(jQuery);